package com.itheima.d2_reflect;

import java.io.File;
import java.lang.reflect.Field;

public class Test3Field {
    public static void main(String[] args) throws Exception {
        Class c=Cat.class;

        Field[] fields= c.getDeclaredFields();
        for(Field field:fields){
            System.out.println(field.getName()+"---->"+field.getType());
        }

        Field fName=c.getDeclaredField("name");
        System.out.println(fName.getName()+"----->"+fName.getType());

        Cat cat=new Cat();
        fName.setAccessible(true);
        fName.set(cat,"咖啡猫");
        System.out.println(cat);

        String name=(String) fName.get(cat);
        System.out.println(name);
    }
}
